//
//  UIWebViewLocalViewController.m
//  UITest
//
//  Created by wp w on 12-6-10.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "UIWebViewLocalViewController.h"
@implementation UIWebViewLocalViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    CGRect webRect = CGRectMake(10,10,300,400);
    UIWebView *myWebView = [[UIWebView alloc] initWithFrame:webRect];
    
    myWebView.delegate = self;
    
    myWebView.scalesPageToFit = NO;
    NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"myPage" ofType:@"html"];
    NSString *htmlContent = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
    
    [myWebView loadHTMLString:htmlContent baseURL:nil];
    
    [self.view addSubview:myWebView];
    
    [myWebView release];
}

- (BOOL)webView:(UIWebView *)webView 
 shouldStartLoadWithRequest:(NSURLRequest *)request 
 navigationType:(UIWebViewNavigationType)navigationType {
    NSURL *pageURL = [request URL];
    
    if ( ([[pageURL scheme] isEqualToString: @"http"]) && (navigationType == UIWebViewNavigationTypeLinkClicked ))
    {
        [[UIApplication sharedApplication] openURL:pageURL];
        return NO;
    }
    
    return YES;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
